<?php
namespace app\index\controller;
use app\index\controller\Base;
use think\Session;
use think\Db;
class Follow extends Base{
// 关注
    public function index(){
        // return $this->fetch('personal');
    	if(!Session::get('username')){
    		$this->success('请先登陆！','Reg/index');
    	}else{
			$username=Session::get('username');
			$info=db('user')->where('username',$username)->select();
			$this->assign('info',$info);
			$us=db('user')->where('username',$username)->column('id');
			$userid=$us[0];
			$s=db('follow')->alias('a')
			->join('user b','a.fans=b.id')
			->where('fans',$userid)
			->column('follow');
			// var_dump($s);
			// exit;
			// $follow=$s[0];
			$sl=db('user')->where('id',$s)->select();
			$this->assign('sl',$sl);
			// var_dump($s);
			// exit;
			// ->select();		
			$this->assign('s',$s);		
    		return $this->fetch('personal/follow');
        }
	}
	public function guanzhu(){
    	if(!Session::get('username')){
    		$this->success('请先登陆！','Login/index');
    	}else{
			$username=Session::get('username');
			$gid=input('gid');				
			$us=Db::name('produce')->where('pid',$gid)->column('userid');
			$userid=$us[0];			
			$user=db('user')
			->where('username',$username)
			->column('id');
			$usid=$user[0];
    		$time=date("Y-m-d H:i:s");
    		$data=[
    			'time'=>$time,
    			'fans'=>$usid,
				'follow'=>$userid,
    		];    		
    		if(db('follow')->insert($data)){
    			$this->success('关注！','Blog/index');   
    		}
    	}
	}
	public function xians(){
		$username=Session::get('username');		
		$user=db('user')
		->where('username',$username)
		->column('id');
		$usid=$user[0];
		var_dump('usid');
		exit;
	}
}